package com.luck.easyfoodbatch.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.mvp.model.PointsModel;
import com.luck.easyfoodbatch.util.Tools;
import com.luck.easyrecyclerview.adapter.BaseViewHolder;
import com.luck.easyrecyclerview.adapter.RecyclerArrayAdapter;

/**
 * author：luck
 * project：LoveCare
 * package：com.tongyu.luck.lovecare.adapter
 * email：893855882@qq.com
 * data：16/8/12
 */
public class PointsAdapter extends RecyclerArrayAdapter<PointsModel.DataBean.ModelsBean> {
    private Context mContext;

    public PointsAdapter(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {

        return new CouponViewHolder(parent);
    }

    public class CouponViewHolder extends BaseViewHolder<PointsModel.DataBean.ModelsBean> {
        TextView tv_content, tv_points, tv_created_at, tv_flag;

        public CouponViewHolder(ViewGroup parent) {
            super(parent, R.layout.points_item);
            tv_content = $(R.id.tv_content);
            tv_points = $(R.id.tv_points);
            tv_created_at = $(R.id.tv_created_at);
            tv_flag = $(R.id.tv_flag);
        }

        @Override
        public void setData(final PointsModel.DataBean.ModelsBean bean, int position) {
            int created_at = bean.getCreated_at();
            String content = bean.getContent();
            String amount = bean.getAmount();
            if (!Tools.isNull(created_at)) {
                tv_created_at.setText(Tools.SubTime2(created_at + ""));
            } else {
                tv_created_at.setText("1970-01-01");
            }
            if (!Tools.isNull(content)) {
                tv_content.setText(content);
            } else {
                tv_content.setText("未知");
            }
            if (!Tools.isNull(amount)) {
                if (amount.startsWith("-")) {
                    tv_flag.setText("");
                } else {
                    tv_flag.setText("+");
                }
                tv_points.setText(amount + "分");
            } else {
                tv_points.setText("");
            }
        }
    }
}
